package a15_memo.black;

import java.util.ArrayList;
import java.util.List;

public class Caller {
	private String state;

	public Memo createMemo() {
		return new Memo(this.state);
	}

	public String getState() {
		return state;
	}

	public void setState(String state1) {
		this.state = state1;
	}

	public void restoreMemo(MemoIF memoIF) {
		this.setState(((Memo) memoIF).popStatus());
	}

	/**
	 *   @author shaoyuxia
	 *
	 */
	private class Memo implements MemoIF {

		private List<String> statusList = new ArrayList<>();

		  Memo(String state) {
			this.statusList.add(state);
		}

		// public void addState(String state) {
		// this.statusList.add(state);
		// }

		  String popStatus() {
			if (this.statusList.size() > 0) {
				return this.statusList.remove(this.statusList.size() - 1);
			}
			return null;
		}

	}
}
